﻿using System;
using System.Linq;

namespace SoftSource.Reactive
{
    public static class ObservableQueueExtensions
    {
        public static IObservable<T> QueueTypedObservable<T>(this ObservableQueue<object> queue, IObservable<T> observable)
        {
            return Observable.CreateWithDisposable<T>(observer =>
                queue.QueueObservable(observable.Select(t => (object)t))
                .Select(value => (T)value)
                .Subscribe(observer));
        }
    }
}
